package com.GUI.Lesson04;


import javax.swing.*;
import java.awt.*;

//图标需要实现类，Frame继承。需要弹窗,接口
public class IconDemo extends JFrame implements Icon {

    //声明宽高
    private int width;
    private int height;
    public IconDemo(){};//无参构造
    public IconDemo(int width,int height){
        this.height = height;
        this.width = width;
    };

    public void init(){
        IconDemo iconDemo = new IconDemo(15, 15);
        //图标可以放在按钮上，也可以放在标签上
        JLabel label = new JLabel("icontest", iconDemo, SwingConstants.CENTER);

        Container container = getContentPane();
        container.add(label);
        this.setVisible(true);
        this.setBounds(20,20,200,200);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new IconDemo().init();
    }

    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
        g.fillOval(x,y,width,height);
    }

    @Override
    public int getIconWidth() {
        return this.width;
    }

    @Override
    public int getIconHeight() {
        return this.height;
    }
}
